﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SingleTileDown;

namespace SingleThreadDownload
{
    class Program
    {
        static void Main(string[] args)
        {
            //https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{0}/{1}/{2}
            //var urlTemplate = Console.ReadLine();
            var urlTemplate = "https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{0}/{1}/{2}";
            var level = 4;
            var attempt = 4;
            var startY = 0;

            try
            {
                urlTemplate = args[0];
            }
            catch (Exception)
            {
            }
            try
            {
                level = int.Parse(args[1]);
            }
            catch (Exception)
            {
            }

            try
            {
                attempt = int.Parse(args[2]);
            }
            catch (Exception)
            {
            }

            try
            {
                startY = int.Parse(args[3]);
            }
            catch (Exception)
            {

            }


            int maxY = ((int)Math.Pow(2, level)) - 1;
            int maxX = maxY;

            try
            {
                maxY = int.Parse(args[4]);
            }
            catch (Exception)
            {
          
            }

            for (int y = startY; y <= maxY; y++)
            {
                for (int x = 0; x <= maxX; x++)
                {
                    SingleTileDown.Program program = new SingleTileDown.Program()
                    {
                        UrlTemplate = urlTemplate,
                        Z = level,
                        Y = y,
                        X = x,
                        Attempt = attempt
                    };
                    program.OnExecute();

                    //new SingleTileDown.Program();





                }
            }

            ;





        }
    }
}
